//
//  LanChaoPro.m
//  AndyDemo
//
//  Created by 千锋 on 15/11/14.
//  Copyright (c) 2015年 千锋. All rights reserved.
//

#import "LanChaoPro.h"

@implementation LanChaoPro

+ (UILabel *)createLabelWith:(CGRect)frame textColor:(UIColor *)color font:(UIFont *)font backgroundColor:(UIColor *)color1 TextAlignment:(NSTextAlignment)textAlignment text:(NSString *)text{
    UILabel * label = [[UILabel alloc]initWithFrame:frame];
    label.text = text;
    label.textColor = color;
    label.backgroundColor =color1;
    label.font = font;
    label.textAlignment = textAlignment;
    label.userInteractionEnabled = YES;
    return label;
}
+ (UIImageView *)createImageViewWithframe:(CGRect)frame image:(NSString *)imageName{
    UIImageView * imageView = [[UIImageView alloc]initWithFrame:frame];
    imageView.image = [UIImage imageNamed:imageName];
    imageView.userInteractionEnabled = YES;
    return imageView;
}
+ (UIButton *)createButtonWithframe:(CGRect)frame titleColor:(UIColor *)titlecolor  backgroundColor:(UIColor *)color font:(UIFont *)font target:(id)target sel:(SEL)sel event:(UIControlEvents)event title:(NSString *)title  backgroundImage:(NSString *)imageName image:(NSString *)imageName1{
    
    UIButton * button = [[UIButton alloc]initWithFrame:frame];
    [button setTitle:title forState:UIControlStateNormal];
    [button setTitleColor:titlecolor forState:UIControlStateNormal];
    [button addTarget:target action:sel forControlEvents:event];
    [button setBackgroundImage:[UIImage imageNamed:imageName] forState:UIControlStateNormal];
    [button setImage:[UIImage imageNamed:imageName1] forState:UIControlStateHighlighted];
    button.backgroundColor = color;
    button.titleLabel.font = font;
    return button;
}
+ (UITextField *)createTextFieldWith:(CGRect)frame borderStyle:(UITextBorderStyle)borderStyle keyborderType:(UIKeyboardType)keyborderType font:(UIFont *)font textColor:(UIColor *)textColor textAlignment:(NSTextAlignment)textAlignment clearButtonMode:(UITextFieldViewMode)clearButtonMode secureTextEntry:(BOOL)secureTextEntry placeHolder:(NSString *)placeholder backgroundImage:(NSString *)imageName{
    UITextField * textField = [[UITextField alloc]initWithFrame:frame];
    //输入框格式
    textField.borderStyle = borderStyle;
    //键盘的格式
    textField.keyboardType = keyborderType;
    
    textField.font = font;
    textField.textColor = textColor;
    textField.textAlignment = textAlignment;
    
    //清空输入的模式
    textField.clearButtonMode = clearButtonMode;
    //输入时是否保密(用于密码输入)
    textField.secureTextEntry = secureTextEntry;
    //提示词
    textField.placeholder = placeholder;
    textField.background = [UIImage imageNamed:imageName];
    return textField;
}

+(UIColor *)randomColorWithAlpha:(CGFloat)alpha{
    
    CGFloat red = (arc4random()%256)/255.f;
    CGFloat green = (arc4random()%256)/255.f;
    CGFloat blue = (arc4random()%256)/255.f;
    
    UIColor * color = [UIColor colorWithRed:red green:green blue:blue alpha:alpha];
    
    return color;
}

//设置导航项上的title
-(void)addNavigationItemTitle:(NSString *)title{
    
    UILabel * titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 100, 44)];
    titleLabel.text = title;
    titleLabel.font = [UIFont systemFontOfSize:20];
    //FF00FF 十六进制
    titleLabel.textColor = [UIColor colorWithRed:1 green:0 blue:1 alpha:1];
    titleLabel.textAlignment = NSTextAlignmentCenter;
    
    //设置navigationItem的titleView
    self.navigationItem.titleView = titleLabel;
}

//设置导航项上的BarButton
-(void)addBarButtonItemWithTarget:(id)targer action:(SEL)selector andName:(NSString *)name isLeft:(BOOL)isLeft{
    
    UIButton * button = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 44, 30)];
    
    [button setBackgroundImage:[UIImage imageNamed:@"buttonbar_action"] forState:UIControlStateNormal];
    
    [button setTitle:name forState:UIControlStateNormal];
    [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    button.titleLabel.font = [UIFont systemFontOfSize:15];
    
    [button addTarget:targer action:selector forControlEvents:UIControlEventTouchUpInside];
    
    //设置导航栏上的按钮
    UIBarButtonItem * buttonItem = [[UIBarButtonItem alloc]initWithCustomView:button];
    
    //判断是否为左侧按钮
    
    if (isLeft) {
        
        self.navigationItem.leftBarButtonItem =buttonItem;
    }else{
        
        self.navigationItem.rightBarButtonItem =buttonItem;
    }
    
    
}



+ (BOOL)isMobileNumber:(NSString *)mobileNum
{
    /**
     * 手机号码
     * 移动：134[0-8],135,136,137,138,139,150,151,157,158,159,182,187,188
     * 联通：130,131,132,152,155,156,185,186
     * 电信：133,1349,153,180,189
     */
    NSString * MOBILE = @"^1(3[0-9]|5[0-35-9]|8[025-9])\\d{8}$";
    /**
     10         * 中国移动：China Mobile
     11         * 134[0-8],135,136,137,138,139,150,151,157,158,159,182,187,188
     12         */
    NSString * CM = @"^1(34[0-8]|(3[5-9]|5[017-9]|8[278])\\d)\\d{7}$";
    /**
     15         * 中国联通：China Unicom
     16         * 130,131,132,152,155,156,185,186
     17         */
    NSString * CU = @"^1(3[0-2]|5[256]|8[56])\\d{8}$";
    /**
     20         * 中国电信：China Telecom
     21         * 133,1349,153,180,189
     22         */
    // NSString * CT = @"^1((33|53|8[09])[0-9]|349)\\d{7}$";
    NSString * CT = @"^1((33|53|8[019])[0-9]|349)\\d{7}$";
    /**
     25         * 大陆地区固话及小灵通
     26         * 区号：010,020,021,022,023,024,025,027,028,029
     27         * 号码：七位或八位
     28         */
    // NSString * PHS = @"^0(10|2[0-5789]|\\d{3})\\d{7,8}$";
    //
    NSString * WL =@"^17\\d{9}$";
    
    NSPredicate *regextestmobile = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", MOBILE];
    NSPredicate *regextestcm = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", CM];
    NSPredicate *regextestcu = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", CU];
    NSPredicate *regextestct = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", CT];
    NSPredicate *regextestwl = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", WL];
    if (([regextestmobile evaluateWithObject:mobileNum] == YES)
        || ([regextestcm evaluateWithObject:mobileNum] == YES)
        || ([regextestct evaluateWithObject:mobileNum] == YES)
        || ([regextestcu evaluateWithObject:mobileNum] == YES)
        || ([regextestwl evaluateWithObject:mobileNum] == YES))
    {
        return YES;
    }
    else
    {
        return NO;
    }
}



@end
